package com.suli.multimedia.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suli.multimedia.entity.Image;
import com.suli.multimedia.entity.vo.ImageVO;
import com.suli.multimedia.enums.ImageType;
import com.suli.multimedia.mapper.ImageMapper;
import com.suli.multimedia.service.ImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SuLi
 * @since 2022-03-23
 */
@Service
@Transactional
public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image> implements ImageService {

    @Autowired
    ImageMapper imageMapper;
    @Override
    public Map<String, Object> getImage() {
        QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("image_type", ImageType.HORSE);
        List<Image> images = imageMapper.selectList(queryWrapper);
        Map<String,Object> map=new HashMap<>();
        map.put("image", images);
        return map;
    }


    @Override
    public boolean insertImage(ImageVO imageVO) {
        imageVO.getImageList().forEach(img ->{
            Image image=new Image(imageVO.getImageName(),imageVO.getImageType(),imageVO.getScenicId());
            image.setImageUrl(img);
           imageMapper.insert(image);
        });
        return true;
    }

    @Override
    public Map<String, Object> getImage(Integer scenicId) {
        QueryWrapper<Image> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("scenic_id", scenicId);
        List<Image> images = imageMapper.selectList(queryWrapper);
        Map<String, Object> map=new HashMap<>();
        map.put("scenicImage", images);
        return map;
    }

    @Override
    public boolean deleteImage(String imageId) {
        int i=imageMapper.deleteByImageId(imageId);
        return i > 0;
    }

    @Override
    public boolean insertHorse(Image image) {
        int insert = imageMapper.insert(image);
        return insert>0;
    }
}
